package com.ycu.jk16.mall.dao;

import static com.ycu.jk16.mall.util.common.AndroidMalConstant.ORDER_DETAIL_TABLE;

import java.util.List;

import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.mapping.FetchType;

import com.ycu.jk16.mall.dao.provider.OrderDetailDynaSqlProvider;
import com.ycu.jk16.mall.domain.OrderDetail;

/**
 * 
 * @ClassName OrderDetail
 * @Description TODO(OrderDetail)
 * @author 倪宗龙
 * @date 2018年12月18日 下午1:59:26
 * @version V1.0
 */
public interface OrderDetailDao {
	// 通过no查询订单详情
	@Select("select * from " + ORDER_DETAIL_TABLE + " where order_no = #{orderNo}")
	@Results({ // 将JavaBean里的变量名与数据库字段名不相符的进行标注
			@Result(column = "id", property = "id", id = true),
			@Result(column = "currentproduct_name", property = "currentProductName"),
			@Result(column = "currentunitprice", property = "currentUnitPrice"),
			@Result(column = "order_no", property = "order", one = @One(select = "com.ycu.jk16.mall.dao.OrderDao.selectByNo", fetchType = FetchType.EAGER)),
			@Result(column = "product_id", property = "product", one = @One(select = "com.ycu.jk16.mall.dao.ProductDao.selectById", fetchType = FetchType.EAGER)), })
	List<OrderDetail> selectDetailByNo(String orderNo);

	// 添加详情订单
	@SelectProvider(type = OrderDetailDynaSqlProvider.class, method = "insertOrderDetail")
	@Results({ // 将JavaBean里的变量名与数据库字段名不相符的进行标注
			@Result(column = "id", property = "id", id = true),
			@Result(column = "currentproduct_name", property = "currentProductName"),
			@Result(column = "currentunitprice", property = "currentUnitPrice"),
			@Result(column = "order_no", property = "order", one = @One(select = "com.ycu.jk16.mall.dao.OrderDao.selectByNo", fetchType = FetchType.EAGER)),
			@Result(column = "product_id", property = "product", one = @One(select = "com.ycu.jk16.mall.dao.ProductDao.selectById", fetchType = FetchType.EAGER)), })
	void addOrderDetail(List<OrderDetail> orderList);

}
